package com.iknow.activity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.User;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.data.QingBo;
import com.iknow.data.SubscribeTag;
import com.iknow.db.IKnowDataBase;
import com.iknow.http.HttpException;
import com.iknow.task.CommonTask.QingboTask;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import com.iknow.view.widget.PullToRefreshListView;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import java.util.List;

public class TagQingboActivity extends QingboWithHeaderActivity
{
  private static final Intent SERVICE_INTENT = new Intent();
  private final int ACTION_SUBSCRIBE;
  private final int ACTION_UNSUBSCRIBE;
  private boolean mBinded;
  private TaskAdapter mListener;
  private ServiceConnection mSvrConn;
  private SubscribeTag mTag;
  private SubscribeTagTask mTagTask;
  private User mUser;
  private IXmppFacade mXmppFacade;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
  }

  public TagQingboActivity()
  {
    this.mSvrConn = new XmppServiceConnection(this, null);
    this.mBinded = false;
    this.ACTION_SUBSCRIBE = 1;
    this.ACTION_UNSUBSCRIBE = 2;
    this.mListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "SubscribeTagTask";
      }

      public void onCancelled()
      {
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        this.this$0.mProgressBar.setVisibility(8);
        this.this$0.mActionButton.setVisibility(0);
        if (paramTaskResult == TaskResult.OK)
          if (TagQingboActivity.access$0(this.this$0).GetActionCode() == 1)
          {
            Toast.makeText(this.this$0, "订阅成功", 0).show();
            this.this$0.mActionButton.setText("取消订阅");
            this.this$0.mActionButton.setTag(Integer.valueOf(2));
          }
        while (true)
        {
          while (true)
          {
            return;
            Toast.makeText(this.this$0, "已取消", 0).show();
            this.this$0.mActionButton.setText("订阅");
            this.this$0.mActionButton.setTag(Integer.valueOf(1));
          }
          Toast.makeText(this.this$0, TagQingboActivity.access$0(this.this$0).getErrorMessage(), 0).show();
        }
      }

      public void onPreExecute()
      {
        this.this$0.mProgressBar.setVisibility(0);
        this.this$0.mActionButton.setVisibility(8);
      }

      public void onProgressUpdate(, Object paramObject)
      {
      }
    };
  }

  List<QingBo> doGetLocolData()
  {
    List localList1;
    Loger.i(this.TAG, "get tag qingbo local");
    if (this.mUser != null);
    try
    {
      Loger.i(this.TAG, "get tag qingbo local");
      List localList2 = IKnow.mApi.getQingboListByTagLocal(this.mTag.getTagName(), 0, 20);
      localList1 = localList2;
      return localList1;
    }
    catch (HttpException localHttpException)
    {
      Loger.e(this.TAG, localHttpException.getMessage());
      localHttpException.printStackTrace();
      localList1 = null;
    }
  }

  void doNeedMore()
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      this.mGetMoreButton.setText("正在载入数据...");
      this.mTask = new CommonTask.QingboTask();
      this.mTask.setListener(this.mGetMoreListener);
      this.mTask.setAdapter(this.mAdapter);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("tags", this.mTag.getTagName());
      localTaskParams.put("offset", Integer.valueOf(getCurrentListLength()));
      localTaskParams.put("length", Integer.valueOf(20));
      CommonTask.QingboTask localQingboTask = this.mTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localQingboTask.execute(arrayOfTaskParams);
    }
  }

  void getServerData()
  {
  }

  void initToolBarText()
  {
    this.mTag = ((SubscribeTag)getIntent().getParcelableExtra("tag"));
    this.mTitle = this.mTag.getTagName();
    if (IKnow.mIKnowDataBase.existSubscribeTag(this.mTag))
      if (((IKnow)getApplication()).isAccountConfigured())
      {
        this.mActionButton.setText("取消订阅");
        this.mActionButton.setTag(Integer.valueOf(2));
      }
    while (true)
    {
      return;
      this.mActionButton.setText("订阅");
      this.mActionButton.setTag(Integer.valueOf(1));
    }
  }

  void onActionButtonClickListener()
  {
    if (this.mUser == null)
      startActivity(new Intent(this, LoginActivity.class));
    while (true)
    {
      do
        return;
      while ((this.mXmppFacade == null) || ((this.mTagTask != null) && (this.mTagTask.getStatus() == AsyncTask.Status.RUNNING)));
      this.mTagTask = new SubscribeTagTask(this, null);
      this.mTagTask.setListener(this.mListener);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("code", (Integer)this.mActionButton.getTag());
      SubscribeTagTask localSubscribeTagTask = this.mTagTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localSubscribeTagTask.execute(arrayOfTaskParams);
    }
  }

  void onBackButtonClickListener()
  {
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.PAGE_TYPE = 3;
    this.TAG = this.mTag + "_TagQingboActivity";
    this.mUser = IKnow.mIKnowDataBase.getUser();
    getLocolData();
  }

  protected void onPause()
  {
    if (this.mBinded)
    {
      unbindService(this.mSvrConn);
      this.mBinded = false;
    }
    super.onPause();
  }

  protected void onResume()
  {
    if ((((IKnow)getApplication()).isAccountConfigured()) && (!(this.mBinded)))
      this.mBinded = bindService(SERVICE_INTENT, this.mSvrConn, 1);
    super.onResume();
  }

  void refreshData()
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      String str = IKnow.mSystemConfig.getString(this.TAG);
      if (!(StringUtil.isEmpty(str)))
        this.mListView.setLastUpdated("更新于" + str);
      this.mTask = new CommonTask.QingboTask();
      this.mTask.setListener(this.mTaskListener);
      this.mTask.setAdapter(this.mAdapter);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("tags", this.mTag.getTagName());
      localTaskParams.put("offset", Integer.valueOf(0));
      localTaskParams.put("length", Integer.valueOf(20));
      CommonTask.QingboTask localQingboTask = this.mTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localQingboTask.execute(arrayOfTaskParams);
    }
  }

  private class SubscribeTagTask extends GenericTask
  {
    private int mActionCode = 1;
    private String mErrorMessage;

    public int GetActionCode()
    {
      return this.mActionCode;
    }

    // ERROR //
    protected TaskResult _doInBackground()
    {
      // Byte code:
      //   0: aload_1
      //   1: iconst_0
      //   2: aaload
      //   3: astore_2
      //   4: aload_0
      //   5: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   8: invokestatic 39	com/iknow/activity/TagQingboActivity:access$1	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/xmpp/service/aidl/IXmppFacade;
      //   11: invokeinterface 45 1 0
      //   16: astore 7
      //   18: aload 7
      //   20: ifnonnull +17 -> 37
      //   23: aload_0
      //   24: ldc 47
      //   26: putfield 49	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mErrorMessage	Ljava/lang/String;
      //   29: getstatic 55	com/iknow/task/TaskResult:FAILED	Lcom/iknow/task/TaskResult;
      //   32: astore 4
      //   34: goto +429 -> 463
      //   37: aload_0
      //   38: aload_2
      //   39: ldc 57
      //   41: invokevirtual 63	com/iknow/task/TaskParams:getInt	(Ljava/lang/String;)I
      //   44: putfield 22	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mActionCode	I
      //   47: aload_0
      //   48: getfield 22	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mActionCode	I
      //   51: iconst_1
      //   52: if_icmpne +182 -> 234
      //   55: getstatic 69	com/iknow/IKnow:mIKnowDataBase	Lcom/iknow/db/IKnowDataBase;
      //   58: aload_0
      //   59: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   62: invokestatic 73	com/iknow/activity/TagQingboActivity:access$2	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/User;
      //   65: invokevirtual 79	com/iknow/User:getUID	()Ljava/lang/String;
      //   68: invokevirtual 85	com/iknow/db/IKnowDataBase:getSubscribeTags	(Ljava/lang/String;)Ljava/util/List;
      //   71: astore 14
      //   73: ldc 87
      //   75: astore 15
      //   77: aload 14
      //   79: ifnull +22 -> 101
      //   82: aload 14
      //   84: invokeinterface 93 1 0
      //   89: astore 18
      //   91: aload 18
      //   93: invokeinterface 99 1 0
      //   98: ifne +91 -> 189
      //   101: new 101	java/lang/StringBuilder
      //   104: dup
      //   105: aload 15
      //   107: invokestatic 107	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
      //   110: invokespecial 110	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   113: aload_0
      //   114: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   117: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   120: invokevirtual 119	com/iknow/data/SubscribeTag:getTagName	()Ljava/lang/String;
      //   123: invokevirtual 123	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   126: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   129: astore 16
      //   131: aload 7
      //   133: invokeinterface 132 1 0
      //   138: aload 16
      //   140: invokeinterface 138 2 0
      //   145: pop
      //   146: aload_0
      //   147: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   150: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   153: ldc 140
      //   155: invokevirtual 143	com/iknow/data/SubscribeTag:setSubscribeFlag	(Ljava/lang/String;)V
      //   158: getstatic 69	com/iknow/IKnow:mIKnowDataBase	Lcom/iknow/db/IKnowDataBase;
      //   161: aload_0
      //   162: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   165: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   168: aload_0
      //   169: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   172: invokestatic 73	com/iknow/activity/TagQingboActivity:access$2	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/User;
      //   175: invokevirtual 79	com/iknow/User:getUID	()Ljava/lang/String;
      //   178: invokevirtual 147	com/iknow/db/IKnowDataBase:addSubscribeTag	(Lcom/iknow/data/SubscribeTag;Ljava/lang/String;)V
      //   181: getstatic 150	com/iknow/task/TaskResult:OK	Lcom/iknow/task/TaskResult;
      //   184: astore 4
      //   186: goto +277 -> 463
      //   189: aload 18
      //   191: invokeinterface 154 1 0
      //   196: checkcast 116	com/iknow/data/SubscribeTag
      //   199: astore 19
      //   201: new 101	java/lang/StringBuilder
      //   204: dup
      //   205: aload 15
      //   207: invokestatic 107	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
      //   210: invokespecial 110	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   213: aload 19
      //   215: invokevirtual 119	com/iknow/data/SubscribeTag:getTagName	()Ljava/lang/String;
      //   218: invokevirtual 123	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   221: ldc 156
      //   223: invokevirtual 123	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   226: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   229: astore 15
      //   231: goto -140 -> 91
      //   234: aload_0
      //   235: getfield 22	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mActionCode	I
      //   238: iconst_2
      //   239: if_icmpne -58 -> 181
      //   242: getstatic 69	com/iknow/IKnow:mIKnowDataBase	Lcom/iknow/db/IKnowDataBase;
      //   245: aload_0
      //   246: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   249: invokestatic 73	com/iknow/activity/TagQingboActivity:access$2	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/User;
      //   252: invokevirtual 79	com/iknow/User:getUID	()Ljava/lang/String;
      //   255: invokevirtual 85	com/iknow/db/IKnowDataBase:getSubscribeTags	(Ljava/lang/String;)Ljava/util/List;
      //   258: astore 8
      //   260: ldc 87
      //   262: astore 9
      //   264: aload 8
      //   266: ifnull +22 -> 288
      //   269: aload 8
      //   271: invokeinterface 93 1 0
      //   276: astore 11
      //   278: aload 11
      //   280: invokeinterface 99 1 0
      //   285: ifne +80 -> 365
      //   288: aload 7
      //   290: invokeinterface 132 1 0
      //   295: aload 9
      //   297: invokeinterface 138 2 0
      //   302: pop
      //   303: getstatic 69	com/iknow/IKnow:mIKnowDataBase	Lcom/iknow/db/IKnowDataBase;
      //   306: aload_0
      //   307: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   310: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   313: aload_0
      //   314: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   317: invokestatic 73	com/iknow/activity/TagQingboActivity:access$2	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/User;
      //   320: invokevirtual 79	com/iknow/User:getUID	()Ljava/lang/String;
      //   323: invokevirtual 159	com/iknow/db/IKnowDataBase:deleteSubscribeTag	(Lcom/iknow/data/SubscribeTag;Ljava/lang/String;)V
      //   326: aload_0
      //   327: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   330: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   333: ldc 161
      //   335: invokevirtual 143	com/iknow/data/SubscribeTag:setSubscribeFlag	(Ljava/lang/String;)V
      //   338: goto -157 -> 181
      //   341: astore 6
      //   343: aload_0
      //   344: aload 6
      //   346: invokevirtual 164	android/os/RemoteException:getMessage	()Ljava/lang/String;
      //   349: putfield 49	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mErrorMessage	Ljava/lang/String;
      //   352: aload 6
      //   354: invokevirtual 167	android/os/RemoteException:printStackTrace	()V
      //   357: getstatic 55	com/iknow/task/TaskResult:FAILED	Lcom/iknow/task/TaskResult;
      //   360: astore 4
      //   362: goto +101 -> 463
      //   365: aload 11
      //   367: invokeinterface 154 1 0
      //   372: checkcast 116	com/iknow/data/SubscribeTag
      //   375: astore 12
      //   377: aload 12
      //   379: invokevirtual 119	com/iknow/data/SubscribeTag:getTagName	()Ljava/lang/String;
      //   382: aload_0
      //   383: getfield 17	com/iknow/activity/TagQingboActivity$SubscribeTagTask:this$0	Lcom/iknow/activity/TagQingboActivity;
      //   386: invokestatic 114	com/iknow/activity/TagQingboActivity:access$3	(Lcom/iknow/activity/TagQingboActivity;)Lcom/iknow/data/SubscribeTag;
      //   389: invokevirtual 119	com/iknow/data/SubscribeTag:getTagName	()Ljava/lang/String;
      //   392: invokevirtual 170	java/lang/String:equalsIgnoreCase	(Ljava/lang/String;)Z
      //   395: ifne -117 -> 278
      //   398: new 101	java/lang/StringBuilder
      //   401: dup
      //   402: aload 9
      //   404: invokestatic 107	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
      //   407: invokespecial 110	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   410: aload 12
      //   412: invokevirtual 119	com/iknow/data/SubscribeTag:getTagName	()Ljava/lang/String;
      //   415: invokevirtual 123	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   418: ldc 156
      //   420: invokevirtual 123	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   423: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   426: astore 13
      //   428: aload 13
      //   430: astore 9
      //   432: goto -154 -> 278
      //   435: astore 5
      //   437: aload_0
      //   438: aload 5
      //   440: invokevirtual 171	com/iknow/http/HttpException:getMessage	()Ljava/lang/String;
      //   443: putfield 49	com/iknow/activity/TagQingboActivity$SubscribeTagTask:mErrorMessage	Ljava/lang/String;
      //   446: aload 5
      //   448: invokevirtual 172	com/iknow/http/HttpException:printStackTrace	()V
      //   451: getstatic 55	com/iknow/task/TaskResult:FAILED	Lcom/iknow/task/TaskResult;
      //   454: astore 4
      //   456: goto +7 -> 463
      //   459: astore_3
      //   460: goto -279 -> 181
      //   463: aload 4
      //   465: areturn
      //
      // Exception table:
      //   from	to	target	type
      //   4	181	341	android/os/RemoteException
      //   189	338	341	android/os/RemoteException
      //   365	428	341	android/os/RemoteException
      //   4	181	435	com/iknow/http/HttpException
      //   189	338	435	com/iknow/http/HttpException
      //   365	428	435	com/iknow/http/HttpException
      //   4	181	459	java/lang/Exception
      //   189	338	459	java/lang/Exception
      //   365	428	459	java/lang/Exception
    }

    public String getErrorMessage()
    {
      return this.mErrorMessage;
    }
  }

  private class XmppServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      TagQingboActivity.access$4(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
    }

    public void onServiceDisconnected()
    {
      TagQingboActivity.access$4(this.this$0, null);
    }
  }
}